﻿//===========================[ 7 / 6 / 2011 LVI ]=============================
//				Copyright c Vitaly Lyaschenko <SkyChameleon@gmail.com>
// 								Header file
// Purpose: инкапсуляция операций над шейдерными программами
//=============================================================================
#pragma once

#include "common.h"
#include "mathlib.h"
#include "cShader.h"

class cShaderProgram
{
	uint m_Program;
    int checkStatus( uint param );
	bool status;
	//std::string nameProgram;

public:
	cShaderProgram() { }
	cShaderProgram( const char* VertFile, const char* fragFile );
	~cShaderProgram(void);

	void create();
	void release();

	void attach( cShader &shader );
	bool link();
	bool validate();
	
	void UseProgram();
	void UnuseProgram();

	uint getID() const { return m_Program; }
	bool getStatus() const { return status; }

///////////////////////////////////////////////////////////////////////////
	int  getLocationUniform( const char* nameUnif );

	int setParameter( const char* nameUnif, int    *V, int num );
	int setParameter( const char* nameUnif, float  *V, int num );

	int  setUniformMatrix2fv( const char* nameUnif, const float *val, int count = 1, bool transpose = 1 );
	bool setUniformMatrix2fv( const int   location, const float *val, int count = 1, bool transpose = 1 );

	int  setUniformMatrix3fv( const char* nameUnif, const float *val, int count = 1, bool transpose = 1 );
	bool setUniformMatrix3fv( const int   location, const float *val, int count = 1, bool transpose = 1 );

	int  setUniformMatrix4fv( const char* nameUnif, const float *val, int count = 1 , bool transpose = 1 );
	bool setUniformMatrix4fv( const int   location, const float *val, int count = 1 , bool transpose = 1 );

	int  setUniform1i( const char* nameUnif, int v0 );
	bool setUniform1i( const int   location, int v0 );

	int  setUniform2i( const char* nameUnif, vec2 V );
	int  setUniform2i( const char* nameUnif, int v0, int v1 );
	bool setUniform2i( const int   location, int v0, int v1 );

	int  setUniform3i( const char* nameUnif, vec3 V );
	int  setUniform3i( const char* nameUnif, int v0, int v1, int v2 );
	bool setUniform3i( const int   location, int v0, int v1, int v2 );

	int  setUniform4i( const char* nameUnif, vec4 V );
	int  setUniform4i( const char* nameUnif, int v0, int v1, int v2, int v3 );
	bool setUniform4i( const int   location, int v0, int v1, int v2, int v3 );

	int  setUniform1f( const char* nameUnif, float val );
	bool setUniform1f( const int location,   float val );

	int  setUniform2f( const char* nameUnif, vec2 V );
	int  setUniform2f( const char* nameUnif, float v0, float v1 );
	bool setUniform2f( const int   location, float v0, float v1 );

	int  setUniform3f( const char* nameUnif, vec3 V );
	int  setUniform3f( const char* nameUnif, float v0, float v1, float v2 );
	bool setUniform3f( const int   location, float v0, float v1, float v2 );

	int  setUniform4f( const char* nameUnif, vec4 V );
	int  setUniform4f( const char* nameUnif, float v0, float v1, float v2, float v3 );
	bool setUniform4f( const int   location, float v0, float v1, float v2, float v3 );
};